<?php namespace Admin\Controller;
use Hdphp\Controller\Controller;
class LoginController extends Controller{
	public function index(){
			if(IS_POST){
			//判断验证码是否正确
//			if(strtolower(Q('post.code')) != strtolower($_SESSION['code'])){
//				View::error('验证码不正确');
//			}
			//1.接收用户名
			$aname = Q('post.aname');
			//2.接收密码
			$apassword = Q('post.apassword','','md5');
			//3.判断用户名是否存在
			$adminModel = new \Common\Model\Admin;
			$data = $adminModel->where("aname='{$aname}'")->find();
			if(!$data) View::error('用户名或密码不存在');
			//4.判断密码是否正确
			if($data['apassword'] != $apassword ) View::error('用户名或密码不存在');
			//5.登陆成功
			$_SESSION['aid'] = $data['aid'];
			$_SESSION['aname'] = $data['aname'];
			View::success('登录成功',U('Index/index'));
		}
   	 View::make();
	}
	//退出
	public function out(){
	    session_unset();
		session_destroy();
		go(U('Login/index'));
	}

}












 ?>